// pages/dealDetailList/dealDetailList.js
let app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        type: '',
        topTitle: '',
        content: []
    },
    nav(e) {
        let type = e.currentTarget.dataset.type
        let item = e.currentTarget.dataset.item
        if(type == 'deal'){
            wx.navigateTo({
                url: '/pages/dealOrderDetail/dealOrderDetail?obj=' + JSON.stringify(item),
            })
        }
        else{
            wx.navigateTo({
              url: '/pages/integralConvertProductDetail/integralConvertProductDetail?pointMallRecordId=' + item.pointMallRecordId,
            })
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        //   let type = options.type
        //   let type = 'integration'
        let type = options.type
        // let clientId = options.clientId
        // let type = 'deal'
        let url, data
        this.setData({
            type
        })
        if (type == 'deal') {
            this.setData({
                topTitle: '交易记录'
            })
            url = '/client/consumptionRecord'
            data = {
              clientId: app.globalData.clientInfo.clientId,
              shopId: app.globalData.shopId,
              pageNum: 0,
              pageSize: 1000
            }
            
        }
        else if (type == 'integration') {
            this.setData({
                topTitle: '积分兑换记录'
            })
            url = '/client/pointRedeemRecord'
            data = {
              clientId: app.globalData.clientInfo.clientId,
              shopId: app.globalData.shopId,
            }
          
        }

        app.globalData.post({
            url,
            data,
            success: (data) => {
                let content = data.data
                if (type == 'integration') {
                    
                }
                else if (type == 'deal') {
                    content = content.map(val => {
                        val.payAmount = (val.payAmount / 100).toFixed(2)
                        return val
                    })
                }
                this.setData({
                    content
                })
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})